/*
 * v1.1 by tonydon site:txdnet.cn
 * netbeansIDE 7.1
 */
package cn.txdnet.txweb.model;

import cn.txdnet.txweb.utils.Constants;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 *
 * @author txdnet
 */
public final class ModelUtil {

    /*
     * @see 
     * 返回javascript Model 对象
     */
    public static TxtModel getJsModel(Object content) {
        return new TxtModel(ViewType.TXT_MODEL_JS, content);
    }
    /*
     * @see 
     * 返回json Model 对象
     */

    public static TxtModel getJsonModel(Object content) {
        return new TxtModel(ViewType.TXT_MODEL_JSON, content);
    }
    /*
     * @see 
     * 返回text Model 对象
     */

    public static TxtModel getTextModel(Object content) {
        return new TxtModel(ViewType.TXT_MODEL_TEXT, content);
    }
    /*
     * @see 
     * 返回html Model 对象
     */

    public static TxtModel getHtmlModel(Object content) {
        return new TxtModel(ViewType.TXT_MODEL_HTML, content);
    }

    /*
     * @see 
     * 返回重定向 Model 对象
     */
    public static PageModel getRedirectModel(String page) {
        return new PageModel(ViewType.PAGE_MODEL_REDIRECT, page);
    }

    /*
     * @see 
     * 返回分发 Model 对象 没有数据传递
     */
    public static PageModel getForwardModel(String page) {
        return new PageModel(ViewType.PAGE_MODEL_FORWARD, page);
    }

    /*
     * @see 
     * 返回分发 Model 对象 有数据传递
     */
    public static PageModel getForwardModel(String page, String name, Map<String, Object> model) {
        return new PageModel(ViewType.PAGE_MODEL_FORWARD, page, name, model);
    }

    public static PageModel getForwardModel(String page, String name, List<Object> model) {
        return new PageModel(ViewType.PAGE_MODEL_FORWARD, page, name, model);
    }

    public static PageModel getForwardModel(String page, String name, String model) {
        return new PageModel(ViewType.PAGE_MODEL_FORWARD, page, name, model);
    }

    public static PageModel getForwardModel(String page, String name, Object model) {
        return new PageModel(ViewType.PAGE_MODEL_FORWARD, page, name, model);
    }

    /*
     * @see 返回veloctiy模型 有数据传递
     */
    public static PageModel getVelocityModel(String vm_file, Map<String, Object> model) {
        return new PageModel(ViewType.PAGE_MODEL_VELOCITY, vm_file, model);
    }

    /*
     * @see 返回veloctiy模型 没有数据传递
     */
    public static PageModel getVelocityModel(String vm_file) {
        return new PageModel(ViewType.PAGE_MODEL_VELOCITY, vm_file);
    }

    /*
     * @see
     * 返回jsp视图，没有数据传递
     */
    public static JspModel getJspModel(String jsp_name) {
        return new JspModel(ViewType.PAGE_MODEL_JSP, jsp_name);
    }

    /*
     * @see 返回数据模型到JSP视图
     */
    public static JspModel getJspModel(String jsp_name, String name, Map<String, Object> model) {
        return new JspModel(ViewType.PAGE_MODEL_JSP, jsp_name, name, model);
    }

    public static JspModel getJspModel(String jsp_name, String name, List<Object> model) {
        return new JspModel(ViewType.PAGE_MODEL_JSP, jsp_name, name, model);
    }

    public static JspModel getJspModel(String jsp_name, String name, String model) {
        return new JspModel(ViewType.PAGE_MODEL_JSP, jsp_name, name, model);
    }

    public static JspModel getJspModel(String jsp_name, String name, Object model) {
        return new JspModel(ViewType.PAGE_MODEL_JSP, jsp_name, name, model);
    }

    public static JspModel getJspModel(String jsp_name, Object model) {
        return new JspModel(ViewType.PAGE_MODEL_JSP, jsp_name, 
                Constants.JSP_ATTR_DEFAULT_NAME, model);
    }
    
    // down model util
    // 下载模型返回
    
    /**
     * 返回文本下载模型
     * @param file_name
     * @param content
     * @return 
     */
    public static DownModel getDownModel(String file_name, String content){
        return new DownModel(ViewType.DOWN_MODEL_PLAIN, file_name, content);
    }
    
    /**
     * 返回文件流二进制下载模型
     * @param file_name
     * @param file_is
     * @return 
     */
    public static DownModel getDownModel(String file_name, InputStream file_is){
        return new DownModel(ViewType.DOWN_MODEL_STREAM, file_name, file_is);
    }
    
}
